package com.googlecode.droidjni;

import android.app.*;
import android.os.Bundle;
import android.view.*;
import android.widget.*;

import static com.googlecode.droidjni.util.*;
import static com.googlecode.droidjni.droid.*;

public class Trace extends Activity {

    private SurfaceView sv;
    private FrameLayout cv;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cv = new FrameLayout(this);
        setContentView(cv);
/*      timing_java(); */
        smokeTests();

        int x = 1000, y = 42;
        int  z = add(x, y);
        trace("The sum of " + x + " and " + y + " is " + z);
        TextView tv = new TextView(this);
        tv.setText( "The sum of " + x + " and " + y + " is " + z );
        sv = new SurfaceView(this);
        cv.addView(sv);
        cv.addView(tv);
    }

    protected void onResume() {
        super.onResume();
        trace("onResume pid=" + android.os.Process.myPid() + " thread=" + Thread.currentThread().getId());
    }

    protected void onPause() {
        super.onPause();
    }

    static int count;

    static void foo() { // best seen ~89 nanoseconds per call
        count++;
    }

    static void timing_java() {
        count = 0;
        timestamp("1,000,000 java calls");
        final int N = 100000;
        for (int i = 0; i < N; i++) {
            foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo(); foo();
        }
        timestamp("1,000,000 java calls");
        assertion(count == N * 10);
        timestamp("1,000,000 jni calls");
        for (int k = 0; k < N; k++) {
            nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
        }
        timestamp("1,000,000 jni calls");
    }


}

